package com.woniu.login.consumer;

import cn.hutool.extra.mail.MailUtil;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.amqp.core.Message;

import java.io.IOException;

@Component
public class EmailConsumer {
    @RabbitListener(queues = "verifycode")
    public void receiveEmailMessage(String str,Channel channel, Message message) throws IOException {
        String[] parts = str.split(";");
        String email = parts[0];
        int code = Integer.parseInt(parts[1]);
        try{
            MailUtil.send(email, "登录测试", "验证码是："+code, false);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }catch (Exception e){
            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
        }

    }
}